#!/bin/bash

while read LINE
do
	#do echo "$LINE"
	if [[ -z "${LINE// }" ]]; then
		echo "$LINE"
	else
		if [[ ${LINE:0:1} == "#" ]] ; then 
			echo "$LINE"; 
		else 
			ip_host=( $LINE )
			#echo "==>" ${ip_host[1]}
			if [ "ip6-localhost" == "${ip_host[1]}" -o "ip6-loopback" == "${ip_host[1]}" -o "localhost" == "${ip_host[1]}" ]; then
				echo "$LINE"; 
			else
				dig ${ip_host[1]} +short | while read IP
				do
					if [[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
						echo $IP ${ip_host[1]}
					fi
				done
				#break
			fi
		fi
	fi
done < hosts.sample
